package com.ysj.demo.accompanynetwork.mvp.model;

import android.util.Log;

import com.google.gson.Gson;
import com.ysj.demo.accompanynetwork.ApiServiceUntil;
import com.ysj.demo.accompanynetwork.bean.LoginBean;
import com.ysj.demo.accompanynetwork.bean.LoginResultBean;
import com.ysj.demo.accompanynetwork.bean.RestRsp;
import com.ysj.demo.accompanynetwork.mvp.common.OnCommonListener;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 登录
 * Created by 80530 on 2018/8/18.
 */

public class LoginModel {

    public void LoginTask(LoginBean bean, final OnCommonListener commonListener) {
        Call<RestRsp<LoginResultBean>> call = ApiServiceUntil.getInstance().getmApi().loginTask(bean);
        call.enqueue(new Callback<RestRsp<LoginResultBean>>() {
            @Override
            public void onResponse(Call<RestRsp<LoginResultBean>> call, Response<RestRsp<LoginResultBean>> response) {
                RestRsp<LoginResultBean> body = response.body();
                Log.i("登录LoginActivity", new Gson().toJson(body));
                commonListener.onSuccessListener(body);
            }

            @Override
            public void onFailure(Call<RestRsp<LoginResultBean>> call, Throwable t) {
                Log.i("LoginActivity", t.toString());
                commonListener.onFailListener(t);
            }
        });
    }
}
